
$.fn.fillForm = function (data) {
    return $(this).find('[data-name]').each(function (i, elem) {
        if (data == null) {
            $(this).reset();
            return;
        }
        var formElem = $(elem);
        var name = formElem.attr('data-name').toLowerCase();
        if (data[name] == undefined) return true;
        var elemType = formElem.get(0).tagName.toLowerCase();
        if (elemType == 'input') {
            elemType = 'input.' + (formElem.attr('type') ? formElem.attr('type').toLowerCase() : 'text');
        }
        var isdisabled = formElem.is(':disabled');
        if (isdisabled) formElem.removeProp('disabled');
        data[name] = data[name] != null ? data[name].toString() : '';
        switch (elemType) {
            case "input.checkbox":
                if (data[name] == "") {
                    formElem.prop('checked', false);
                } else {
                    //数组查找元素
                    if (data[name].indexOf(formElem.val().toLowerCase()) > -1 || data[name].indexOf(formElem.attr('value').toLowerCase()) > -1) {
                        formElem.prop('checked', true);
                    } else {
                        formElem.prop('checked', false);
                    }
                }
                break;
            case "input.radio":
                if (data[name] == "") {
                    formElem.prop('checked', false);
                } else if (formElem.val().toLowerCase() == data[name] || formElem.attr('value').toLowerCase() == data[name]) {
                    formElem.prop('checked', true);
                }
                break;
            case "select":
                Xms.Web.SelectedValue(formElem, data[name]);
                formElem.attr('data-value', data[name]);
                break;
            case "input.text":
            case "input.hidden":
            case "textarea":
                formElem.val(data[name]);
                break;
            case "input.button":
            case "button":
                break;
            default:
                formElem.text(data[name]);
        }
        if (isdisabled) formElem.prop('disabled', 'disabled');
    });
};